//
//  SettingViewController.m
//  EasyBuy
//
//  Created by Zhu Xiangjun on 10/7/12.
//  Copyright (c) 2012 shen donghao. All rights reserved.
//

#import "SettingViewController.h"
#import "SettingTableView.h"
#import "SettingTableViewCell.h"
#import "ImageCacheSupport/ImageLoadView.h"
#import "WeiboLoginViewController.h"

@interface SettingViewController (){
    SettingTableView *settingTableView;
    ImageLoadView *userIconView;
}

@end

@implementation SettingViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {

    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.title = @"个人中心";
    
    UIImageView *userView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 70)];
    userView.backgroundColor = [UIColor blueColor];
    [self.view addSubview:userView];
    [userView release];
    

    SettingTableView *_settingTableView = [[SettingTableView alloc] initWithFrame:CGRectMake(0, 70, 320, 300) style:UITableViewStyleGrouped];
    _settingTableView.delegate = self;
    _settingTableView.dataSource = self;
    settingTableView = _settingTableView;
    [self.view addSubview:settingTableView];
    [_settingTableView release];
    
    
}


- (void)viewDidUnload
{
    [super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    switch (section) {
        case 0:
            
            return 1;
            
        case 1:
            
            return 3;
            
        case 2:
            
            return 3;
    }
    return 0;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 3;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *CellIdentifier = @"cellId";
    SettingTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (!cell) {
        cell = [[SettingTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    
    if(indexPath.section == 0){
        
        [cell initCellData:@"新浪微博" :1];
        
    }else if(indexPath.section ==1){
        
        switch (indexPath.row) {
            case 0:
                [cell initCellData:@"我发布的宝贝" :0];
                break;
                
            case 1:
                [cell initCellData:@"草稿箱" :0];
                break;
            case 2:
                [cell initCellData:@"喜欢的宝贝" :0];
                break;
        }
    }else if(indexPath.section ==2){
        
        switch (indexPath.row) {
            case 0:
                [cell initCellData:@"清除本地缓存" :0];
                break;
                
            case 1:
                [cell initCellData:@"版本信息" :0];
                break;
            case 2:
                [cell initCellData:@"意见反馈" :0];
                break;
        }
    }
    
    
    
    //    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.section == 0){
        GHWeiboEngine *weiboEngine = WB_ENGINE;
        WeiboLoginViewController *weiboLoginViewController = [[[WeiboLoginViewController alloc] initWithWeiboEngine:weiboEngine] autorelease];
        [self.navigationController pushViewController:weiboLoginViewController animated:YES];
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 34;
}

@end
